package com.mobrite.domaindroid.util;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager.NameNotFoundException;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.mobrite.domaindroid.R;

public class UiHelper {

	Activity activity;

	public UiHelper(Activity activity) {
		super();
		this.activity = activity;
	}
	
	public void showAboutDialog() {
		
        final Dialog dialog = new Dialog(activity);
        dialog.setContentView(R.layout.about_dialog);
        dialog.setTitle("About");
        
        dialog.setCancelable(true);
        //set up text

        TextView text = (TextView) dialog.findViewById(R.id.TextView01);
		String version;
		try {
			version = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName;
		} catch (NameNotFoundException e) {
			version = "1.0";
		}

        text.setText("WHOIS Client and Domain Availability Lookup Tool for Android.\n\nVersion "+version+"\nBuild Number: "+activity.getResources().getString(R.string.build_number));
        //set up image view

        ImageView img = (ImageView) dialog.findViewById(R.id.ImageView01);
        img.setImageResource(R.drawable.icon);
        //set up button
        Button button = (Button) dialog.findViewById(R.id.Button01);
        button.setOnClickListener(new OnClickListener() {
        @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        //now that the dialog is set up, it's time to show it    
        dialog.show();

    }
	
	public void showRegistrarList(DialogInterface.OnClickListener listener) {
				
		new AlertDialog.Builder(activity).setItems(RegistrarHelper.REGISTRAR_LIST, listener)
						.setTitle("Select Registrar")						
						.show();
	}
}
